home *** CD-ROM | disk | FTP | other *** search
- Path: solon.com!not-for-mail
- From: Samuel Oosterhuis <soosterh@uoguelph.ca>
- Newsgroups: comp.lang.c,comp.lang.c.moderated,hp.unix,comp.sys.hp.apps,comp.sys.hp.hpux
- Subject: Re: C coding problem
- Date: 16 Mar 1996 09:20:11 -0600
- Organization: UoGuelph
- Sender: clc@solutions.solon.com
- Approved: clc@solutions.solon.com
- Message-ID: <4iem7b$9u6@solutions.solon.com>
- References: <4ianbf$h86@solutions.solon.com>
- NNTP-Posting-Host: solutions.solon.com
- X-Mailer: Mozilla 2.0 (Win95; I)
-
- Stephen Proctor wrote:
- > I am trying to write a *simple* C program and am running into the following
- > warning problem shown below. Why do I get this warning?[snippage]
- > main(int argc, char *argv[])
- > {
- > int ii;
- > int option_val = 0;
- > /* skip lines */
- > for (ii=1; ii<argc; ii++) {
- > /* skip lines */
- > /* The next line is the offending line */
- > if (*argv[ii] == '-') option_val = read_options;
- > /* skip lines */
- > return 0; /* Program executed successfully */
- > }
-
- First of all I suggest that you read some of the K & R examples.
- There is a good example of dealing with this exact type of problem
- on page 117 of the second edition. But for your immediate problem
- you might try rewriting your for loop as follows:
-
- /* loop once for each parameter */
- while( --argc > 0 ){
- /* check if the parameter starts with '-' */
- if((*++argv)[0] == '-' )
- option_val = read_options;
- /* rest of the loop stuff */
- }
-
- In your program you were pointer at the string that contained the
- full parameter not just the first character of that string.
-
- Samuel (soosterh@uoguelph.ca)
-
- [Note that the example contains an error, which is that it increments
- argv[n]. -mod]
-